package com.quick.calcu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quick.calcu.entity.Teacher;
import com.quick.calcu.entity.User;
import com.quick.calcu.mapper.TeacherMapper;
import com.quick.calcu.service.TeacherService;
import com.quick.calcu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Autowired
    private UserService userService;

    @Override
    public Teacher getByUserId(Long userId) {
        LambdaQueryWrapper<Teacher> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Teacher::getUserId, userId);
        return getOne(wrapper);
    }

    @Override
    public Teacher getWithUser(Long teacherId) {
        Teacher teacher = getById(teacherId);
        if (teacher == null) {
            return null;
        }

        User user = userService.getById(teacher.getUserId());
        teacher.setUser(user);

        return teacher;
    }
}